<?php

class ComptableController extends Zend_Controller_Action
{

    public function init() {
        /* Initialize action controller here */
    }

    public function listercAction() {
        $lesComptables = new Application_Model_DbTable_Comptable();
        $select = $lesComptables->select();
        $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbTableSelect($select));
        $paginator->setItemCountPerPage(10);
        $currentPage = isset($_GET['page']) ? (int) htmlentities($_GET['page']) : 1;
        $paginator->setCurrentPageNumber($currentPage);
        $this->view->paginator = $paginator;
        $this->view->lesComptables = $lesComptables;
        $this->view->addScriptPath('.');
        $this->view->setEscape('htmlentities');
        $this->view->setEncoding('ISO-8859-1');
    }
    
    public function gerercAction(){
        $lesComptables = new Application_Model_DbTable_Comptable();
        $select = $lesComptables->select();
        $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbTableSelect($select));
        $paginator->setItemCountPerPage(10);
        $currentPage = isset($_GET['page']) ? (int) htmlentities($_GET['page']) : 1;
        $paginator->setCurrentPageNumber($currentPage);
        $this->view->paginator = $paginator;
        $this->view->lesComptables = $lesComptables;
        $this->view->addScriptPath('.');
        $this->view->setEscape('htmlentities');
        $this->view->setEncoding('ISO-8859-1');
    }

    public function ajoutercAction() {
        $form = new Application_Form_Comptable();
        $form->envoyer->setLabel('Ajouter');
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $id = $form->getValue('id');
                $nom = $form->getValue('nom');
                $prenom = $form->getValue('prenom');
                $login = $form->getValue('login');
                $mdp = $form->getValue('mdp');
                $adresse = $form->getValue('adresse');
                $cp = $form->getValue('cp');
                $ville = $form->getValue('ville');
                $dateEmbauche = $form->getValue('dateEmbauche');
                $role = $form->getValue('role');
                $lesComptables = new Application_Model_DbTable_Comptable();
                $lesComptables->ajouterComptable($id, $nom, $prenom, $login, $mdp, $adresse, $cp, $ville, $dateEmbauche, $role);
                $this->_helper->redirector('gererc');
            } else {
                $form->populate($formData);
            }
        }
    }

    public function modifiercAction() {
        $form = new Application_Form_Comptable();
        $form->envoyer->setLabel('Modifier');
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $id = $form->getValue('id');
                $nom = $form->getValue('nom');
                $prenom = $form->getValue('prenom');
                $login = $form->getValue('login');
                $mdp = $form->getValue('mdp');
                $adresse = $form->getValue('adresse');
                $cp = $form->getValue('cp');
                $ville = $form->getValue('ville');
                $dateEmbauche = $form->getValue('dateEmbauche');
                $role = $form->getValue('role');
                $lesComptables = new Application_Model_DbTable_Comptable();
                $lesComptables->modifierComptable($id, $nom, $prenom, $login, $mdp, $adresse, $cp, $ville, $dateEmbauche, $role);
                $this->_helper->redirector('gererc');
            } else {
                $form->populate($formData);
            }
        } else {
            $id = $this->_getParam('id', 0);
            $lesComptables = new Application_Model_DbTable_Comptable();
            $form->populate($lesComptables->obtenirComptable($id));
        }
    }

    public function supprimercAction() {
        if ($this->getRequest()->isPost()) {
            $supprimer = $this->getRequest()->getPost('supprimer');
            if ($supprimer == 'Oui') {
                $id = $this->getRequest()->getPost('id');
                $lesComptables = new Application_Model_DbTable_Comptable();
                $lesComptables->supprimerComptable($id);
            }
            $this->_redirect('/comptable/gererc');
        } else {
            $id = $this->_getParam('id', 0);
            $lesComptables = new Application_Model_DbTable_Comptable();
            $this->view->comptable = $lesComptables->obtenirComptable($id);
        }
    }


}









